<!--  -->
<template>
    <div>
        <Card>
            <div slot="title" >
                <Button v-if="btnp.cdxjian_fqxj" @click="handleClickAddForm" class="zh-hollow" type="primary" icon="plus-round">发起巡检</Button>
            </div>
            <Form :model="formItem" :label-width="70">
                <Row :gutter="10" type="flex"  align="middle"  >
                    <Col span="8">
                        <FormItem label="巡检单">
                            <Input v-model="formItem.code" placeholder="单号" clearable></Input>
                        </FormItem>
                    </Col>
                    <Col span="8" v-if="user_type!=='01'">
                        <FormItem label="客户">
                            <Select v-model="formItem.customerUuid" @on-change="searchCustomerChange" filterable>
                                <Option  v-for="item in moreCustomerList" :value="item.uuid" :key="item.uuid+'cus'">{{ item.name }}</Option>
                            </Select>
                        </FormItem>
                    </Col>
                    <Col span="8">
                        <FormItem label="机构">
                            <Input @on-focus="s_tree=true;" :disabled="!formItem.customerUuid||formItem.customerUuid=='全部'" v-model="formItem.instName" placeholder="请选择机构" readonly></Input>
                            <!-- <Select :disabled="!formItem.customerUuid||formItem.customerUuid=='全部'" v-model="formItem.inst_uuid" filterable>
                                <Option  v-for="item in moreMechanismList" :value="item.uuid" :key="item.uuid+'mec'">{{ item.name }}</Option>
                            </Select> -->
                        </FormItem>
                    </Col>
                <!-- </Row>
                <Row :gutter="10" type="flex" justify="space-between" align="middle"  > -->
                <Col span="8">
                    <FormItem label="进度">
                        <Select v-model="formItem.state" >
                            <Option  v-for="item in progressList" :value="item.state" :key="item.state+'progressa'">{{ item.desc }}</Option>
                        </Select>
                    </FormItem>
                </Col>
                <Col span="8">
                    <FormItem label="预警">
                        <Select v-model="formItem.progressState" >
                            <Option  v-for="item in warningList" :value="item.state" :key="item.state+'warning'">{{ item.desc }}</Option>
                        </Select>
                    </FormItem>
                </Col>
                <Col span="12">
                    <FormItem label="发起时间">
                        <DatePicker v-model="search.timeRange" format="yyyy-MM-dd HH:mm" type="datetimerange" placement="bottom-end" placeholder="请选择开始和结束时间"></DatePicker>
                    </FormItem>
                </Col>
                <!-- </Row>
                <Row :gutter="10"  > -->
                <Col span="12"  >
                    <FormItem label="所在地">
                        <Cascader change-on-select v-model="search.location" placeholder="请选择省市区" :data="areasData" ></Cascader>
                    </FormItem>
                </Col>
                
                </Row>
                <Row :gutter="10" >
                <Col span="8" offset="16"  style="text-align:right;">
                    <Button class="zh-hollow" type="primary" icon="ios-search-strong" @click="handleClickgetTable">搜索</Button>
                    <!-- <Button v-if="btnp.cdxjian_dc" class="zh-hollow" type="warning" style="margin-left:25px;" @click='download'>导出EXCEL</Button> -->
                    <a v-if="btnp.cdxjian_dc" :href="downLoadUrl" target="_blank"><Button  class="zh-hollow" type="warning" style="margin-left:25px;" > 导出EXCEL </Button></a>
                </Col>
                
                </Row>
            </Form>
        </Card>
        <Card style="margin-top:10px;" :padding="0">
            <Table :loading="loading" border :columns="columns" :data="data"></Table>
            <Page :current.sync="formItem.pageNumber"  :total="total" show-total show-sizer @on-change="pageChange" @on-page-size-change="pageSizeChange"></Page>
        </Card>
        <!-- 进度对话框 -->
        <progressModal 
        :width="520"
        :zhmodel="modal_progress" 
        title="巡检进度" 
        :totalTime="progress_details.totalTime"
        :columns="modal_columns"
        :data="progress_details.data"
        @change="change"
        >
        </progressModal>
        <!-- 分配 -->
         <distribuModal
            title="分配巡检单"
            :zhmodel="modal_distribu_sheet"
            :optionsArrayF="proList.list1"
            :optionsArrayS="proList.list2"
            :formData="distribuForm"
            :data="distribu_sheet.records"
            @giveUpAction="giveUpActionClick"
            @change="distribuChange"
            @confirmDistribu="clickDistribuClick"
        >
        </distribuModal>
        <!-- 发起巡检 -->
        <Modal title="发起巡检" v-model="modal_add_check_form"   :mask-closable="false" class="zh-modal-form" >
            <!-- <p slot="header" >发起巡检</p> -->
            <Form :model="addForm" :label-width="80" style="padding:20px;">
                <FormItem label="所在地*">
                    <Cascader change-on-select @on-change="repaireCascaderChange" v-model="addForm.location" placeholder="请选择省市区" :data="areasData" ></Cascader>
                </FormItem>
                <FormItem label="客户*" v-if="user_type!=='01'">
                    <Select v-model="addForm.customerUuid" filterable @on-change="formCustomerChange" :disabled="!addForm.province">
                        <Option  v-for="item in customerList" :value="item.uuid" :key="item.uuid+'customer'">{{ item.name }}</Option>
                    </Select>
                </FormItem>
                <FormItem label="机构*">
                    <Card :padding="0" v-if="selected_mechanism.length>0" @click="change_mechanism_tree">
                        <Tag style="margin:5px;"  v-for="item in selected_mechanism"  :key="item.inst_uuid+'tag'">{{item.inst_name}}</Tag>
                    </Card>
                    <Button v-if="user_type!=='01'" :disabled="!addForm.customerUuid.length>0" type="text" @click="change_mechanism_tree">选择机构</Button>
                    <Button v-else :disabled="!addForm.location[0]" type="text" @click="change_mechanism_tree">选择机构</Button>
                </FormItem>
                <FormItem label="巡检模板*">
                    <Select :disabled="!addForm.customerUuid"  v-model="addForm.templet" >
                        <Option  v-for="item in templetList" :value="item.inspection_item_uuid" :key="item.inspection_item_uuid+'template'">{{ item.name }}</Option>
                    </Select>
                </FormItem>
                <FormItem label="预计完成*">
                    <DatePicker :options="options"  v-model="addForm.time" type="date"></DatePicker>
                   
                </FormItem>
                <FormItem label="分配给*">
                    <Select style="textAlign:auto;" :disabled="!addForm.customerUuid.length>0" v-model="addForm.pro" filterable >
                        <Option class="zh-flex-5 zh-flex" v-for="item in addproList" :value="item.value" :key="item.order+'pro'">{{item.name}}</Option>
                        
                    </Select>
                </FormItem>
                <FormItem label="备注">
                    <Input :maxlength="20" v-model="addForm.remarks" ></Input>
                </FormItem>
            </Form>
              <div slot="footer">
                <div class="zh-flex zh-flex-5" >
                    <Button @click="giveUpSaveInspection" type="ghost">放弃操作</Button>
                    <Button @click="saveInspectionForm" class="zh-hollow" type="primary" >保存</Button>
                </div>
                
            </div>
        </Modal>
        <Modal title="选择机构"  v-model="mechanism_tree" @on-ok="confirmTree" :mask-closable="false"  class-name="vertical-center-modal">
            <!-- <p slot="header" >选择机构</p> -->
            <div style="padding:15px 30px;">
                <Tree ref="jgtree" :data="treeData" show-checkbox multiple @on-check-change="checkChange" ></Tree>
            </div>
               
        </Modal>
        <!-- 巡检详情 -->
        <Modal title="巡检详情" width="450" v-model="modal_check_details" class="zh-modal-form no_footer_modal" class-name="vertical-center-modal">
            <!-- <p slot="header" >巡检详情</p> -->
            <Form :label-width="100" style="padding:20px;">
                <FormItem label="预计完成时间">{{check_details.time}}</FormItem>
                <FormItem label="巡检模板">{{!!check_details.templet?check_details.templet:'未添加'}}</FormItem>
                <FormItem label="联系人">
                    <span  v-if="!check_details.concatPeople">未添加</span>
                    <span v-if="!!check_details.concatPeople">{{check_details.concatPeople}}({{check_details.mobile}})</span>
                    <Button style="marginLeft:15px;" @click="handleClickChangePeople" v-if="!!check_details.concatPeople&&isChangeBtn" size="small">更换</Button>
                </FormItem>
                <div class="detail-other zh-flex zh-flex-3" v-if="!!check_details.evaluate&&!!check_details.evaluate.skill">
                    <div class="detail-other-item"><label>专业技能：</label>{{check_details.evaluate.skill}}</div>
                    <div class="detail-other-item"><label>响应速度：</label>{{check_details.evaluate.speed}}</div>
                    <div class="detail-other-item"><label>服务态度：</label>{{check_details.evaluate.service}}</div>
                    <!-- <div class="detail-other-item"><label>其他评价：</label>{{check_details.evaluate.other}}</div> -->
                </div>
                <div class="detail-other zh-flex zh-flex-3" v-if="!!check_details.evaluate&&!!check_details.evaluate.skill">
                    <div class="detail-other-item" style="width:100%"><label>其他评价：</label>{{check_details.evaluate.other}}</div>
                </div>
            </Form>
        </Modal>
        <!-- 更换联系人 -->
        <Modal title="更换联系人" @on-ok="updateContact" ok-text="保存"  cancel-text="放弃操作" width="450" v-model="modal_change_people" class="zh-modal-form" class-name="vertical-center-modal">
            <!-- <p slot="header" >更换联系人</p> -->
            <Form :model="changePeopleForm" :label-width="100" style="padding:20px;">
                <FormItem label="联系人手机号">
                    <Input v-model="changePeopleForm.mobile" @on-change="mobileChange" ></Input>
                </FormItem>
                <FormItem label="姓名">
                    <Input :readonly="changePeopleFormReadonly" v-model="changePeopleForm.name" ></Input>
                </FormItem>
            </Form>
        </Modal>
        <!-- 巡检报告 -->
        <Modal title="巡检报告"  v-model="modal_report" class="zh-modal-form no_footer_modal" >
            <!-- <p slot="header">巡检报告</p> -->
            <div style="minHeight:500px;">
                <Tabs class="checkTabs" v-if="modal_report">
                <TabPane label="巡检信息" name="information">
                    <div  class=" zh-flex zh-flex-3 zh-flex-6 report-item">
                        <span>银行</span>
                        <p>{{report_base_info.bank_name}}</p>
                    </div>
                    <div  class=" zh-flex zh-flex-3 zh-flex-6 report-item">
                        <span>机构</span>
                        <p>{{report_base_info.instName}}</p>
                    </div>
                    <div  class=" zh-flex zh-flex-3 zh-flex-6 report-item">
                        <span>巡检时间</span>
                        <p>{{report_base_info.start_time}}</p>
                    </div>
                    <div  class=" zh-flex zh-flex-3 zh-flex-6 report-item">
                        <span>报告时间</span>
                        <p>{{report_base_info.end_time}}</p>
                    </div>
                    <div  class=" zh-flex zh-flex-3 zh-flex-6 report-item">
                        <span>运维人员</span>
                        <p>{{report_base_info.proName}}({{report_base_info.proMobile}})</p>
                    </div>
                    <div  class=" zh-flex zh-flex-3 zh-flex-6 report-item">
                        <span>确认人</span>
                        <p>{{report_base_info.contact_name}}({{report_base_info.contact_mobile}})</p>
                    </div>
                </TabPane>
                <TabPane v-if="error_details.length>0" label="异常汇总" name="error">
                    <div v-for="(child) in error_details" :key="child.item_uuid" class=" zh-flex zh-flex-3 zh-flex-6 report-item">
                            <span>{{child.name}}</span>
                            <p class="orange">{{child.value}}</p>
                    </div>
                </TabPane>
                <TabPane v-for="item in report_details" :key="item.item_uuid" :label="item.item_name" :name="item.item_name">
                        <div v-for="(child) in item.children" :key="child.item_uuid" class=" zh-flex zh-flex-3 zh-flex-6 report-item">
                            <span>{{child.name}}</span>
                            <p :class="child.result!=1?'orange':''">{{child.value}}</p>
                        </div>
                </TabPane>
                 <TabPane v-if="!!suggest_detail.text||suggest_detail.imageList.length>0" label="意见与建议" name="suggest">
                     <p  v-if="!!suggest_detail.text" style="padding:10px 20px;">{{suggest_detail.text}}</p>
                     <div style="padding:0 20px;" v-if="suggest_detail.imageList.length>0" class="zh-flex zh-flex-wrap zh-flex-5">
                            <img @click="lookLargeImg(child)" v-for="(child,i) in suggest_detail.imageList" :key="'images'+i" :src="child" alt="" style="width:140px;height:140px;cursor:pointer;margin:5px;">
                    </div>
                 </TabPane>
            </Tabs>
            </div>
            
            <!-- <div slot="footer" >
                <div style="textAlign:ceter;width:">
                    <Button  class="zh-hollow" type="primary" icon="ios-download-outline">下载完整报告</Button>
                </div>
                
            </div> -->
        </Modal>
        <Modal title="查看图片" v-model="look_pic_wrap.look_pic" class="no_footer_modal">
            <img style="width:100%;" :src="look_pic_wrap.src" alt="">
        </Modal>
        <Modal title="选择机构" v-model="s_tree" @on-ok="confirmST" :mask-closable="false" >
			<div style="padding:15px 30px;">
				<Tree :data="s_tree_data"   @on-select-change="s_selectChange"></Tree>
			</div>
		</Modal>
    </div>
</template>

<script>
    import {url_check} from '@/libs/downLoadUrl'
    import accounting from 'accounting'
    import progressModal from '@/components/modal/progressModal.vue'
    import distribuModal from '@/components/modal/distribuModal.vue'
    import util from '@/libs/util'
    import {
        getInspec,
        getInspectionDetails,
        getFPPros,
        getInspectionRecords,
        getBankOrg,
        gettemplateList,
        getCustomerListByLocation,
        getProsByCustomer,
        getOrgTree,
        getUserInfoByMobile,
        getInspecProgress,
        getInspectionProTime,
        getInspRecords,
        getInspecPros,
        getInspecReport,
        downloadInspection
    } from '@/libs/get.js'
    import {
        getInspecTableData,
        saveInspection,
        changeContact,
        saveInspecFP,
        revokeInspection,
        cancleInspection
    } from '@/libs/post.js'
    export default {
        name:'check',
        components:{
            progressModal,
            distribuModal
    },
    data () {
        return {
            s_select_op:[],
			s_tree_data:[],
			s_tree:false,
			downLoadUrl:url_check,
            btnp:{},
            btn:{
                cdxjian_fqxj:false,
                cdxjian_dc:false,
                cdxjian_xq:false,
                cdxjian_jd:false,
                cdxjian_fp:false,
                cdxjian_cx:false,
                cdxjian_ch:false,
                cdxjian_bg:false
            },
            userUuid:'',
            isChangeBtn:true,
            changePeopleFormReadonly:false,
            options: {
                disabledDate (date) {
                    return date && date.valueOf() < Date.now() - 86400000;
                }
            },
            selectList:[],
            saveFormClick:true,
            fpCanClick:true,
            /**判断是否是客户 */
            user_type:'',
            /** 查看图片*/
            look_pic_wrap:{
                look_pic:false,
                src:''
            },
            /**巡检报告 */
            modal_report:false,
            report_base_info:{
                bank_name:'',
                instName:'',
                start_time:'',
                end_time:'',
                proName:'',
                proMobile:'',
                contact_name:'',
                contact_mobile:'',
            },
            suggest_detail:{
                text:'',
                imageList:[]
            },
            error_details:[],
            report_details:[],
            /**更换联系人 */
            modal_change_people:false,
            changePeopleForm:{
                uuid:'',
                mobile:'',
                name:''
            },
            /**巡检详情 */
            modal_check_details:false,
            empty_check_details:{},
            check_details:{
                time:'',
                templet:'',
                mobile:'',
                concatPeople:'',
                evaluate:{
                    skill:'',
                    speed:'',
                    service:'',
                    other:''
                }
            },
            /**发起巡检 */
            modal_add_check_form:false,
            addForm:{
                location:[],
                customerUuid:'',
                templet:'',
                time:'',
                pro:'',
                remarks:'',
                province:'',
                city:'',
                district:'',
                inst_uuid:[],
                inst_name:[]
            },
            templetList:[],
            /**树形结构选择 */
            selected_mechanism:[],
            mechanism_tree:false,
            treeData: [],
            /**分配维修单 */
            modal_distribu_sheet:false,
            distribu_sheet_columns:[
                {
                key:'operator',
                title:'操作人',
                width:80
                },
                {
                key:'action',
                title:'操作',
                width:80
                },
                {
                key:'nextOperator',
                title:'分配/转介给',
                width:110
                },
                {
                key:'time',
                title:'时间'
                },
                {
                key:'remarks',
                title:'备注'
                }
            ],
            distribu_sheet:{
                records:[
                {
                    operator:'admin',
                    action:'分配',
                    nextOperator:'林日曦',
                    time:'2016-07-29 02:03',
                    remarks:'检查一下线路，容易松动'
                },
                {
                    operator:'林日曦',
                    action:'转介',
                    nextOperator:'',
                    time:'2016-07-29 02:03',
                    remarks:'不会处理'
                }
                ]
            },
            distribuForm:{
                uuid:'',
                candidate:'',
                content:''
            },
            addproList:[],
            proList:{
                list1:[],
                list2:[]
            },
            /**进度 */
            modal_progress:false,
            progress_details:{
                totalTime:'1天',
                data:[]
            },
            loading:true,
            total:0,
            search:{
                timeRange:[],
                location:[]
            },
            formItem:{
                code:'',
                customerUuid:'全部',
                inst_uuid:'全部',
                instName:'',
                progressState:'全部',
                state:'全部',
                province:'',
                city:'',
                district:'',
                startTime:'',
                endTime:'', 
                pageSize:10,
                pageNumber:1
            },
            customerList:[],
            moreCustomerList:[{uuid:'全部',name:'全部'}],
            mechanismList:[{uuid:'',name:''}],
            moreMechanismList:[{uuid:'全部',name:'全部'}],
            progressList:[{state:'全部',desc:'全部'}],
            warningList:[{state:'全部',desc:'全部'}],
            areasData:this.$store.state.user.areaData,
            columns:[
                {
                    key:'code',
                    title:'巡检单号',
                    fixed:'left',
                    width:150
                },
                {
                    key:'area',
                    title:'所在地',
                    width:200
                },
                {
                    key:'customerName',
                    title:'客户',
                    width:150
                },
                {
                    key:'inst_name',
                    title:'机构',
                    width:150
                },
                {
                    key:'created',
                    title:'发起时间',
                    width:150
                },
                {
                    key:'state_name',
                    title:'进度',
                    width:80
                },
                {
                    key:'progress_state',
                    title:'预警',
                    width:90,
                    render:(h,params)=>{
                        let tcolor="#000";
                        if(params.row.progress_state!=='正常'){
                        tcolor='#EA7004';
                        }
                        return h('p',{
                            style:{
                            color:tcolor
                            }
                        },params.row.progress_state)
                    
                    }
                },
                {
                key:'action',
                title:'操作',
                align:'center',
                width:200,
                fixed:'right',
                render:(h,params)=>{
                    let uuid=params.row.uuid;
                    //判断是否显示某些操作按钮
                    let state=params.row.state;
                    let dfp=this.btnp.cdxjian_fp?state==="00"?'inline-block':'none':'none';
                    let ch='none';
                    if(this.btnp.cdxjian_ch&&(state==="01"|state==="10"||state==="20")){
                        ch='inline-block'
                    }
                    let rp='none';
                    if(this.btnp.cdxjian_bg&&(state==='90'||state==='99')){
                        rp='inline-block'
                    }
                    return h('div',[
                    h('Button',{
                        props:{
                        type:'text',
                        size:'small'
                        },
                        style:{
                        color:'#2D8CF0',
                        display:this.btnp.cdxjian_xq?'inline-block':'none'
                        },
                        on:{
                        click:()=>{
                            this.getDetails(uuid);
                            this.changePeopleForm.uuid=uuid;
                            if(params.row.state=='90'||params.row.state=='99'||params.row.state=='98'){
                                this.isChangeBtn=false;
                            }else{
                                this.isChangeBtn=true;
                            }
                        }
                        }
                    },'详情'),
                    h('Button',{
                        props:{
                        type:'text',
                        size:'small'
                        },
                        style:{
                        color:'#2D8CF0',
                        display:this.btnp.cdxjian_jd?'inline-block':'none'
                        },
                        on:{
                        click:()=>{
                            this.getInspecPg(uuid);
                        }
                        }
                    },'进度'),
                    h('Button',{
                        props:{
                        type:'text',
                        size:'small'
                        },
                        style:{
                        color:'#2D8CF0',
                        display:dfp
                        },
                        on:{
                        click:()=>{
                            this.distribuForm.uuid=uuid;
                            this.fpModal(uuid,params.row.inst_uuid);
                        }
                        }
                    },'分配'),
                    h('Button',{
                        props:{
                        type:'text',
                        size:'small'
                        },
                        style:{
                        color:'#2D8CF0',
                        display:rp
                        },
                        on:{
                        click:()=>{
                            
                            this.handlegetReport(uuid);
                        }
                        }
                    },'报告'),
                    h('Button',{
                        props:{
                        type:'text',
                        size:'small'
                        },
                        style:{
                        color:'#2D8CF0',
                        display:ch
                        },
                        on:{
                        click:()=>{
                            
                            let config={
                            title:'撤回维修单',
                            content:'将维修单撤回到待分配状态，可以重新分配。',
                            okText:'撤回',
                            cancelText:'放弃操作',
                            onOk:()=>{
                                this.handleRevokeInspection(uuid);
                            }
                            }
                            this.$Modal.confirm(config)
                        }
                        }
                    },'撤回'),

                    h('Button',{
                        props:{
                        type:'text',
                        size:'small'
                        },
                        style:{
                            color:'#EA0000',
                            display:this.btnp.cdxjian_cx?state==="00"?'inline-block':'none':'none'
                        },
                        on:{
                        click:()=>{
                        
                            let config={
                            title:'撤销维修单',
                            content:'将维修单撤销后，维修任务结束，无法恢复。',
                            okText:'撤销',
                            cancelText:'放弃操作',
                            onOk:()=>{
                                this.handlecCancleInspection(uuid);
                            }
                            }
                            this.$Modal.confirm(config)
                        }
                        }
                    },'撤销')
                    ])
                }
                }
                
            ],
            data:[],
            modal_columns:[
                {
                key:'state_name',
                title:'操作',
                width:80
                },
                {
                key:'time',
                title:'时间'
                },
                {
                key:'used_time',
                title:'耗时'
                },
                {
                key:'customer_name',
                title:'操作人'
                }
            ],
        };
    },
    methods:{
        init(){
            let that=this;
            util.isCustomer(this);
            this.empty_check_details=JSON.parse(JSON.stringify(this.check_details));
            let timer;
			if(that.user_type!=='01'){
				timer=setInterval(()=>{
					if(that.$store.state.user.customer.length>0){
						that.moreCustomerList=[{name:'全部',uuid:'全部'},...that.$store.state.user.customer];
						clearInterval(timer)	
					}
				},500);
			}else{
				this.searchCustomerChange(this.userUuid);	
            }
            
            // setTimeout(()=>{
            //     //that.areasData=that.$store.state.user.areaData;
            //     if(this.user_type!='01'){
            //         that.moreCustomerList=[{name:'全部',uuid:'全部'},...that.$store.state.user.customer];
            //     }
                
            // },5000);
            //  if(this.user_type=='01'){
        
            //     this.newSearchCustomerChange(this.userUuid,'search');
                
            // }
            
        },
        async getSearchInstTree(value){
            this.formItem.inst_uuid='';
            this.formItem.instName='';
            this.s_select_op=[];
			if(value!=='全部'){
				let res=await getOrgTree(value);
				let response=res.data;
				if(response.code===200){
					this.s_tree_data=util.tree([response.data]);
				}else{
					this.$Notice.error({
						title: '获取机构失败',
						desc:response.msg
					});
				}
			}
		},
		s_selectChange(selectarr){
			console.log(selectarr);
			this.s_select_op=selectarr;
		},
		confirmST(){
			if(this.s_select_op.length>0){
                this.formItem.inst_uuid=this.s_select_op[0].value;
                this.formItem.instName=this.s_select_op[0].title;
			}else{
				this.formItem.inst_uuid='';
				this.formItem.instName='';
			}
		},
        async download(){
            let res=await downloadInspection();
            let response=res.data;
            if(response.code===200){
                
            }else{
                this.$Notice.error({
                title: '请求出错',
                desc:response.msg
                });
                return false
            }
        },
        async handlegetReport(uuid){
            let res=await getInspecReport(uuid);
            let response=res.data;
            if(response.code===200){
                let {
                    bank_name,
                    instName,
                    start_time,
                    end_time,
                    proName,
                    proMobile,
                    contact_name,
                    contact_mobile}=response.data.base;
                this.report_base_info={
                    bank_name,
                    instName,
                    start_time,
                    end_time,
                    proName,
                    proMobile,
                    contact_name,
                    contact_mobile};
                this.report_details=response.data.categories.map(item=>{
                    item.children=item.children.map(child=>{
                        child.value=(child.result==='1'?child.good_text:child.bad_text)+'；'+child.description;
                        return child
                    })
                    return item
                })
                if(response.data.Expection.length>0){
                    this.error_details=response.data.Expection.map(item=>{
                        item.value=(item.result==='1'?item.good_text:item.bad_text)+'；'+item.description;
                        return item
                    })
                }else{
                    this.error_details=[];
                }
                this.suggest_detail.text=response.data.base.suggestion;
                if(response.data.images_url.length>0){
                    this.suggest_detail.imageList=response.data.images_url.filter(item=>{
                        if(item!=''){
                            return item
                        }
                    }).map(item=>{
                        return response.data.domain+item
                    })
                }else{
                    this.suggest_detail.imageList=[];
                }
                
                this.modal_report=true;
            }else{
                this.$Notice.error({
                title: '请求出错',
                desc:response.msg
                });
                return false
            }
        },
        async getInspecPg(uuid){
            if(await this.getProgress(uuid)&&await this.getTimeDifference(uuid)){
                this.modal_progress=true;
            }
        },
        async getProgress(uuid){
            let res=await getInspecProgress(uuid);
            let response=res.data;
            if(response.code===200){
                this.progress_details.data=response.data.rows.map(item=>{
                    item.time=item.created.slice(0,16);
                    item.used_time=!!item.used_time?item.used_time:'';
                    return item
                })
                return true
            }else{
                this.$Notice.error({
                title: '请求出错',
                desc:response.msg
                });
                return false
            }
        },
        async getTimeDifference(uuid){
            let res=await getInspectionProTime(uuid);
            let response=res.data;
            if(response.code===200){
                this.progress_details.totalTime=response.data.time;
                return true
            }else{
                this.$Notice.error({
                title: '请求出错',
                desc:response.msg
                });
                return false
            }
        },
        async mobileChange(e){
            this.changePeopleFormReadonly=false;
            if(this.changePeopleForm.mobile.length===11){
                let res=await getUserInfoByMobile(this.changePeopleForm.mobile);
                let response=res.data;
                if(response.code===200){
                    if(!!response.data.name){
                        this.changePeopleForm.name=response.data.name;
                        this.changePeopleFormReadonly=true;
                    }
                    
                }else{
                    this.$Notice.error({
                        title: '请求出错',
                        desc:response.msg
                    });
                }
            }
        },
        async updateContact(){
            let contactMobile=this.changePeopleForm.mobile;
            let contactName=this.changePeopleForm.name;
            let uuid=this.changePeopleForm.uuid;
            const reg=this.$store.state.app.mobileReg;
            if(!contactMobile){
                this.$Notice.error({
                    desc:'请输入手机号'
                })
            }else if(!reg.test(contactMobile)){
                this.$Notice.error({
                    desc:'手机号格式错误'
                })
            }else if(contactMobile==this.check_details.mobile){
                this.$Notice.error({
                    desc:'不可更换为相同的手机号'
                })
            }else if(!contactName){
                this.$Notice.error({
                    desc:'请输入姓名'
                })
            }else{
                let res=await changeContact({contactMobile,contactName,uuid});
                let response=res.data;
                if(response.code===200){
                    this.check_details.concatPeople=contactName;
                    this.check_details.mobile=contactMobile;
                }else{
                    this.$Notice.error({
                    title: '请求出错',
                    desc:response.msg
                    });
                    
                }
            }
            
        },
        async getInstTree(uuid){

            let res=await getOrgTree(uuid,this.addForm.province,this.addForm.city,this.addForm.district);
            let response=res.data;
            if(response.code===200){
                this.treeData=util.tree([response.data]);
            }else{
                this.$Notice.error({
                title: '请求出错',
                desc:response.msg
                });    
            }
        },
        async repaireCascaderChange(value,selectedData){
            if(!!value){
                this.addForm.province=value[0];
                this.addForm.city=value[1];
                this.addForm.district=value[2];
                //更新客户列表，如果客户已选则清空
                if(this.user_type!='01'){
                    let res= await getCustomerListByLocation(value[0],value[1],value[2]);
                    let response=res.data;
                    if(response.code===200){
                        this.customerList=response.data;
                        this.addForm.customerUuid='';
                    }else{
                        this.$Notice.error({
                            title: '请求出错',
                            desc:response.msg
                        });
                    }
                }else{
                    this.getInstTree(this.userUuid,value[0],value[1],value[2]);
                    this.getTemplateOptions(this.userUuid);
                    this.getPros(this.userUuid);
                }
                
            }else{
                this.addForm.province='';
                this.addForm.city='';
                this.addForm.district='';
                this.customerList=[];
                this.templetList=[];
                this.addForm.templet='';
                this.addproList=[];
                this.addForm.pro='';
                this.treeData=[];
            }
            
        },
        async formCustomerChange(value){
            if(!!value){
                await this.getTemplateOptions(value);
                await this.getPros(value);
                await this.getInstTree(value);
            }
            
        },
        async getPros(inst_uuid){
            let res=await getProsByCustomer(inst_uuid);
            let response=res.data;
            if(response.code===200){
                this.addproList=response.data;
            }else{
                this.$Notice.error({
                title: '请求出错',
                desc:response.msg
                });
                return false
            }
        },
        async getTemplateOptions(inst_uuid){
            let res=await gettemplateList(inst_uuid);
            let response=res.data;
            if(response.code===200){
                this.templetList=response.data.inspectionTemplates;
                if(this.templetList.length==1){
                    this.addForm.templet=this.templetList[0].inspection_item_uuid;
                }
                if(this.templetList.length==1){
                    this.$Notice.warning({
                        title:'当前客户没有巡检模板',
                        desc:'请在巡检配置中添加巡检模板'
                    })
                }
            }else{
                this.$Notice.error({
                title: '请求出错',
                desc:response.msg
                });
                return false
            }
        },
        /**发起巡检 */
        resetAddform(){
            for(let key in this.addForm){
                if(key=="location"||key=='inst_uuid'||key=='inst_name'){
                    this.addForm[key]=[]
                }else{
                this.addForm[key]=''
                }
            }
        },
        giveUpSaveInspection(){
            this.modal_add_check_form=false;
            this.resetAddform();
        },
        async saveInspectionForm(){
            if(!this.addForm.province){
                this.$Notice.error({
                        desc:'请选择所在地'
                    });
            }else if(this.user_type!='01'&&(!this.addForm.customerUuid||this.addForm.customerUuid.length<=0)){
                this.$Notice.error({
                        desc:'请选择要巡检的客户'
                    });
            }else if(this.addForm.inst_uuid.length<=0){
                this.$Notice.error({
                        desc:'请选择要巡检的机构'
                    });
            }else if(!this.addForm.templet){
                this.$Notice.error({
                        desc:'请选择巡检模板'
                    });
            }else if(!this.addForm.time){
                this.$Notice.error({
                        desc:'请选择预计完成时间'
                    });
            }else if(!this.addForm.pro){
                this.$Notice.error({
                        desc:'请选择运维人员'
                    });
            }else if(this.saveFormClick){
                this.saveFormClick=false;
                let form={
                    inst_uuid:this.addForm.inst_uuid.join(','),
                    inst_name:this.addForm.inst_name.join(','),
                    item_uuid:this.addForm.templet,
                    candidate:this.addForm.pro,
                    remark:this.addForm.remarks,
                    time_to_use:util.time1(this.addForm.time).slice(0,11),
                }
                let res=await saveInspection(form);
                let response=res.data;
                if(response.code===200){
                    this.resetAddform();
                    this.modal_add_check_form=false;
                    this.$Notice.success({
                        desc:'巡检发起成功'
                    });
                    this.formItem={
                        code:'',
                        customerUuid:'全部',
                        inst_uuid:'全部',
                        progressState:'全部',
                        state:'全部',
                        province:'',
                        city:'',
                        district:'',
                        startTime:'',
                        endTime:'', 
                        pageSize:10,
                        pageNumber:1
                    }
                    this.getTable();
                }else{
                    this.$Notice.error({
                        title: '请求出错',
                        desc:response.msg
                    });
                }
                this.saveFormClick=true;
            }
            
        },
        /**分配人员列表 */
        async fpModal(uuid,inst_uuid){
            if(await this.getFPZJRecords(uuid)&& await this.getFPZJproslist(uuid,inst_uuid)){
                this.modal_distribu_sheet=true;
            }
        },
        async getFPZJRecords(uuid){
            let res=await getInspRecords(uuid);
            let response=res.data;
            if(response.code===200){
                if(response.data.rows.length>0){
                    this.distribu_sheet.records=response.data.rows.map(item=>{
                        return {
                            operator:item.ustomer_name,
                            action:item.state_name,
                            nextOperator:item.assignTo,
                            time:item.created.slice(0,16),
                            remarks:item.raw_content
                        }
                    })
                }else{
                    this.distribu_sheet.records=[]
                }  
                return true
            }else{
                this.$Notice.error({
                    title: '请求出错',
                    desc:response.msg
                });
                return false
            }
        },
        async getFPZJproslist(uuid,inst_uuid){
            let res=await getInspecPros(uuid,inst_uuid);
            let response=res.data;
            if(response.code===200){
                let list=response.data;
                this.proList.list1=list.filter(item=>{
                    if(item.class==='同城'){
                        let dis=accounting.unformat(item.distance);
                    
                        let dw='m'
                        if(dis>=1000){
                        dis=dis/1000;
                        dw='km'
                        }
                        dis=accounting.toFixed(dis,2);
                        dis=accounting.formatNumber(dis,3,' ');
                        item.distance=`${dis}${dw}`;
                        return item
                    }
                })
                this.proList.list2=list.filter(item=>{
                    if(item.class==='异地'){
                        let dis=accounting.unformat(item.distance);
                        let dw='m'
                        if(dis>=1000){
                        dis=dis/1000;
                        dw='km'
                        }
                        dis=accounting.toFixed(dis,2);
                        dis=accounting.formatNumber(dis,3,' ');
                        item.distance=`${dis}${dw}`;
                        return item
                    }
                })
                
                return true
            }else{
                this.$Notice.error({
                title: '请求出错',
                desc:response.msg
                });
                return false
            }
        },
        /**详情 */
        async getDetails(uuid){
            this.check_details=this.empty_check_details;
            let res=await getInspectionDetails(uuid);
            let response=res.data;
            if(response.code===200){  
                this.check_details.time=response.data.time;
                if(response.data.contactList.length>0){
                    this.check_details.mobile=response.data.contactList[0].contact_mobile;
                    this.check_details.concatPeople=response.data.contactList[0].contact_name;
                    this.check_details.templet=response.data.inspectionTemplates;
                }
                if(!!response.data.score){
                    this.check_details.evaluate={
                        skill:response.data.score.skill_score,
                        speed:response.data.score.speed_score,
                        service:response.data.score.attitude_score,
                        other:response.data.score.content
                    }
                }else{
                    this.check_details.evaluate={
                        skill:'',
                        speed:'',
                        service:'',
                        other:''
                    }
                }
                this.modal_check_details=true;


            }else{
                this.$Notice.error({
                        title: '请求出错',
                        desc:response.msg
                    });
            }
        },
        async getConditionList(){
            let res=await getInspec();
            let response=res.data;
            if(response.code===200){
                this.progressList=[{state:'全部',desc:'全部'},...response.data.status];
                this.warningList=[{state:'全部',desc:'全部'},...response.data.progressList];
            }else{
            this.$Notice.error({
                title: '请求出错',
                desc:response.msg
            });
            return false
            }
        },
        searchCustomerChange(value){
            //this.newSearchCustomerChange(value,'search')
            this.s_select_op=[];
			this.getSearchInstTree(value);
        },
        async newSearchCustomerChange(value,type){
            
            if(value!=='全部'){
                let res;
                if(type=='search'){
                    res =await getBankOrg(value,'','','')
                }else{
                    res =await getBankOrg(value,this.addForm.province,this.addForm.city,this.addForm.district)
                }
                if(res.status===200){
                    let response=res.data;
                    if(response.code===200){
                        if(type==='search'){
                            this.moreMechanismList=[{uuid:'全部',name:'全部'},...response.data]
                        }else if(type==='form'){
                            this.mechanismList=response.data
                        }     
                    }else{
                        this.$Notice.error({
                            title: '请求出错',
                            desc:response.msg
                        });
                    }
                }else{
                    this.$Notice.error({
                        title: '请求失败'
                    });
                } 

            }else{
                this.formItem.inst_uuid='';
            }
        },
        pageSizeChange(size){
        //回到第一页
            this.formItem.pageNumber=1;
            this.formItem.pageSize=size;
            this.getTable();
        },
        pageChange(number){
            this.formItem.pageNumber=number;
            this.getTable();
        },
        handleClickgetTable(){
            this.formItem.pageNumber=1;
            this.getTable();
        },
        async getTable(){
            this.loading=true;
            let form=JSON.parse(JSON.stringify(this.formItem));
            for(let key in form){
                if(form[key]==='全部'){
                form[key]='';
                }
            }
            if(!!this.search.timeRange[0]&&this.search.timeRange.length>0){
                form.startTime=util.time1(this.search.timeRange[0]);
                form.endTime=util.time1(this.search.timeRange[1]);
            }else{
                form.endTime='';
                form.startTime='';
            }
            if(this.search.location.length>0&&!!this.search.location[0]){
                form.province=this.search.location[0];
                form.city=this.search.location[1];
                form.district=this.search.location[2];
            }else{
                form.province='';
                form.city='';
                form.district='';
            }
            let res=await getInspecTableData(form);
            if(res.status===200){
                let response=res.data;
                if(response.code===200){
                    
                    this.total=response.data.total;
                    this.data=response.data.rows
                    this.loading=false;
                    this.downLoadUrl=`${url_check}${util.pjArgu(form)}`
                    
                }else{
                    this.$Notice.error({
                        title: '请求出错',
                        desc:response.msg
                    });
                }
            }else{
                this.$Notice.error({
                    title: '请求失败'
                });
            } 
        },
        lookLargeImg(src){
            this.look_pic_wrap.look_pic=true;
            this.look_pic_wrap.src=src;
        },
        handleClickChangePeople(){
            this.modal_change_people=true;
        },
        confirmTree(){
            this.selected_mechanism=this.selectList;
            
            this.addForm.inst_uuid=this.selectList.map(item=>{
                return item.inst_uuid
            })
            this.addForm.inst_name=this.selectList.map(item=>{
                return item.inst_name
            })
            
        },
        change_mechanism_tree(){
            this.mechanism_tree=true;
        },
        checkChange(checkarr){
            let list=util.jiangw(checkarr)
            this.selectList=list;
            
        },
        handleClickAddForm(){
            this.modal_add_check_form=true;
        },
        change(active){
            this.modal_progress=active;
        },
        distribuChange(active){
            this.modal_distribu_sheet=active;
        },
        giveUpActionClick(){
            this.modal_distribu_sheet=false;
            this.distribuForm={
                uuid:'',
                candidate:'',
                content:''
            }
        },
        async handleRevokeInspection(uuid){
            let res=await revokeInspection(uuid);
            let response=res.data;
            if(response.code===200){
                this.$Notice.success({
                    desc:'撤回成功'
                });
                this.getTable();
            }else{
                this.$Notice.error({
                    title: '请求出错',
                    desc:response.msg
                });
            }
        },
        async handlecCancleInspection(uuid){
            let res=await cancleInspection(uuid);
            let response=res.data;
            if(response.code===200){
                this.$Notice.success({
                    desc:'撤销成功'
                });
                this.getTable();
            }else{
                this.$Notice.error({
                    title: '请求出错',
                    desc:response.msg
                });
            }
        },
        async clickDistribuClick(){
            if(!this.distribuForm.candidate||this.distribuForm.candidate.length<=0){
                this.$Notice.error({
                    desc:'请选择分配人员'
                })
            }else if(this.fpCanClick){
                this.fpCanClick=false;
                let {uuid,candidate}=this.distribuForm;
                let remark=this.distribuForm.content;
                let res=await saveInspecFP({uuid,candidate,remark});
                let response=res.data;
                if(response.code===200){
                    this.distribuForm={
                        uuid:'',
                        candidate:'',
                        content:''
                    }
                    this.modal_distribu_sheet=false;
                }else{
                    this.$Notice.error({
                        title: '请求出错',
                        desc:response.msg
                    });
                }
                this.fpCanClick=true;
            }
        }
    },
    watch:{
        modal_change_people:function(){
            if(!this.modal_change_people){
                this.changePeopleForm.mobile='';
                this.changePeopleForm.name='';
            }
        },
        modal_add_check_form:function(){
            if(!this.modal_add_check_form){
                this.resetAddform();
                this.selected_mechanism=[];
            }
        }
    },
    created(){
        this.init();
        this.getConditionList();
        this.formItem.progressState=this.$route.query.state?this.$route.query.state:'全部';
        this.getTable();
        this.btnp=util.bpower(this,this.btn);
        
        /**暂时写这 获取巡检模板列表成功时*/
        
    }

    }

</script>
<style lang='scss' >
    .report-item{
        padding:15px 30px;
        span{
            margin-right:30px;
            width:35%;
        }
        .orange{
            color:#FF9900;
        }
        
    }
    .checkTabs .ivu-tabs-tabpane{
        max-height:500px;
        overflow-y:auto;
    }
</style>